/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 28
 * Time: 15:00
 */
//牛客 对称的二叉树
class TreeNode {
    int val = 0;
    TreeNode left = null;
   TreeNode right = null;
   public TreeNode(int val) {
      this.val = val;
    }
  }
public class Solution1 {
    //法一 官方推荐方法
    public boolean isSymmetrical (TreeNode pRoot) {
        if(pRoot == null) return true;
        return isSymmetricalF(pRoot.left, pRoot.right);
    }
    public boolean isSymmetricalF (TreeNode root1, TreeNode root2) {
        if(root1 == null && root2 == null) return true;
        if(root1 == null || root2 == null || root1.val != root2.val) {//在条件中root1.val!=root2.val要放在最后
            return false;
        }
        return isSymmetricalF (root1.left, root2.right) && isSymmetricalF (root1.right, root2.left);//重点
    }
}
